package com.gruopbuying.agent.service.impl;

import com.gruopbuying.agent.dao.UserDao;
import com.gruopbuying.agent.dao.UserRoleDao;
import com.gruopbuying.agent.pojo.UserDO;
import com.gruopbuying.agent.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    UserDao userMapper;
    @Autowired
    private UserRoleDao userRoleMapper;

    @Override
    public List<UserDO> list(Map<String, Object> map) {
        return userMapper.list (map);
    }

    @Override
    public UserDO get(Long id) {
        List<Long> roleIds = userRoleMapper.listRoleId(id);
        UserDO user = userMapper.get(id);
        user.setroleIds(roleIds);
        return user;
    }

    @Override
    public int count(Map<String, Object> map) {
        return userMapper.count(map);
    }

    @Override
    public boolean exits(Map<String, Object> params) {
        boolean exits = userMapper.list(params).size() > 0;
        return exits;
    }
}
